package com.erp.programmer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.erp.programmer.bean.CodeMsg;
import com.erp.programmer.dao.SaleOrderDetailMapper;
import com.erp.programmer.domain.SaleOrder;
import com.erp.programmer.domain.PurchaseOrder;
import com.erp.programmer.domain.PurchaseOrderDetail;
import com.erp.programmer.domain.SaleOrderDetail;
import com.erp.programmer.dto.*;
import com.erp.programmer.enums.PaymentStateEnum;
import com.erp.programmer.enums.StorageStateEnum;
import com.erp.programmer.service.ISaleOrderDetailService;
import com.erp.programmer.utils.CommonUtil;
import com.erp.programmer.utils.CopyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Takagi3
 * @since 2021-05-24
 */
@Service
public class SaleOrderDetailServiceImpl extends ServiceImpl<SaleOrderDetailMapper, SaleOrderDetail> implements ISaleOrderDetailService {

    @Autowired
    SaleOrderDetailMapper saleOrderDetailMapper;

    @Override
    public ResponseDto<List<SaleOrderDetailDto>> search(SaleOrderDto saleOrderDto) {

        //业务逻辑用户点击详情  传进订单  根据订单ID 查询所属所有详单  返回详单列表

        //声明详单列表
        List<SaleOrderDetailDto> saleOrderDetailDtoList = new ArrayList<>();
        //设置条件选择器
        QueryWrapper<SaleOrderDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("sale_order_number", saleOrderDto.getId());

        //查询
        List<SaleOrderDetail> saleOrderDetailListDb = saleOrderDetailMapper.selectList(queryWrapper);
        //转换为Dto
        saleOrderDetailDtoList = CopyUtil.copyList(saleOrderDetailListDb, SaleOrderDetailDto.class);

        return ResponseDto.success(saleOrderDetailDtoList);
    }
}
